package com.kauidao.manageweb.feign.dictionary;

import com.kuaidao.common.constant.SysErrorCodeEnum;
import com.kuaidao.common.entity.IdEntity;
import com.kuaidao.common.entity.IdsEntity;
import com.kuaidao.common.entity.JSONResult;
import com.kuaidao.common.entity.PageBean;
import com.kuaidao.sys.dto.dictionary.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * author Hao
 **/
@FeignClient(name = "sys-server",path = "/sys/dictionaryItem",fallback = DictionaryItemFeignClient.HystrixClientFallback.class)
public interface DictionaryItemFeignClient {

    @PostMapping("/findDictionaryItemByPage")
    public JSONResult<PageBean<DictionaryItemResDTO>>  findDictionaryItemByPage(@RequestBody DictionaryItemReqDTO dictionaryItemReqDTO);

    @Component
    static class HystrixClientFallback implements DictionaryItemFeignClient{

        private JSONResult fallBackError(String name){
            return new JSONResult().fail(SysErrorCodeEnum.ERR_REST_FAIL.getCode(), SysErrorCodeEnum.ERR_REST_FAIL.getMessage());
        }

        @Override
        public JSONResult<PageBean<DictionaryItemResDTO>> findDictionaryItemByPage(DictionaryItemReqDTO dictionaryItemReqDTO) {
            return fallBackError("字典主题词条查询错误");
        }
    }


}
